package org.example.config;

import org.example.filter.MyFilter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.GatewayFilterSpec;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.cloud.gateway.route.builder.UriSpec;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class GatewayConfig {
    //路由配置的另一种方案  通过bean进行注入配置，与yml配置共存时，配置类优先
    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder){
        return builder.routes()
                .route(p -> p.path("/user/discovery")
                        .filters(filterSpec -> filterSpec.filter(new MyFilter(),0)
//                                .addRequestHeader("X-Response-Default-Foo","Default-Bar")
                        )
                        .uri("http://localhost:8001")
                        .id("user_router3"))
                .build();
    }
}
